package ru.example.netcracker.model.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Notification  extends Task implements Serializable {
    
    private String id;    
    private String name;    
    private String description;    
    private Date date;    
    private boolean show;
    
    private final List<Contact> contacts;

    public Notification() {
        contacts = new ArrayList<>();
    }
    
    public Notification(String id) {
        this.id = id;
        this.date = new Date(System.currentTimeMillis());
        contacts = new ArrayList<>();
    }

    public Notification(String id, String name, String description, Date date) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.date = date;
        contacts = new ArrayList<>();
    }

    public Notification(String id, String name, String description, Date date, List<Contact> contacts) {
        this.id = id;
        this.name = name;
        this.description = description;
        this.date = date;
        this.contacts = contacts;
    }
    
    @Override
    public boolean isEnd() {
        return (date.getTime() - System.currentTimeMillis()) > 0;
    }
    
    @XmlAttribute(name = "id")
    @Override
    public String getId() {
        return id;
    }

    @Override
    public void setId(String id) {
        this.id = id;
    }
    
    @XmlAttribute(name = "name")
    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @XmlAttribute(name = "description")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {    
        this.description = description;
    }
    
    @XmlAttribute(name = "date")
    @Override
    public Date getDate() {
        return date;
    }

    @Override
    public void setDate(Date date) {
        this.date = date;
    }

    @XmlAttribute(name = "show")
    @Override
    public boolean isShow() {
        return show;
    }

    @Override
    public void setShow(boolean show) {
        this.show = show;
    }

    @XmlElement(name = "contact")
    public List<Contact> getContacts() {
        return contacts;
    }

    public void addContact(Contact contact) {
        contacts.add(contact);
    }

    public void removeContact(Contact contact) {
        contacts.remove(contact);
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + Objects.hashCode(this.id);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Notification other = (Notification) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Notification{" + "id=" + id + ", name=" + name + ", description=" + description + ", date=" + date + ", show=" + show + ", contacts=" + contacts + '}';
    }
    
    
}


